<template>
  <div class="container">
    <van-sticky :offset-top="44">
      <van-tabs v-model="active" color="rgb(42,177,165)">
        <van-tab title="借记卡" name="1"></van-tab>
        <van-tab title="信用卡" name="2"></van-tab>
      </van-tabs>
      <div class="card" v-for="(item, index) in listData" :key="index">
        <div class="header">
          <div>
            <span class="classify-icon">{{item.id}}类</span>
            <span class="card-no">{{item.card_no|formatCard}}</span>
            <!-- <span class="tips">123456</span> -->
          </div>
          <div class="qrcode">
            <van-icon name="qr" color="rgb(42,177,165)" size="28px" />
          </div>
        </div>
        <div class="content">
          <div class="surplus">人民币可用余额<van-icon name="arrow" /></div>
          <div class="value">
            <span v-show="!item.eyeStatus">{{item.money}}</span>
            <span v-show="item.eyeStatus">****</span>
            <van-icon name="eye" class="eye" v-show="item.eyeStatus" @click="handleEyeChange(item, true)" />
            <van-icon name="closed-eye" class="eye" v-show="!item.eyeStatus" @click="handleEyeChange(item, false)" />
          </div>
        </div>
        <div class="footer">
          <div @click="go('/pages/detail/detail', item)">查询明细</div>
          <div>我要转账</div>
          <div>我要理财</div>
        </div>
      </div>
    </van-sticky>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: '1',
      listData: []
    }
  },
  onLoad() {
    this.init();
  },
  methods: {
    init() {
      let data = {

      }
      this.$q.cardLits(data)
      .then(res=>{
        this.listData = res.map(v=>{
          return {
            ...v,
            eyeStatus: false
          }
        });
      })
    },
    handleEyeChange(item, status) {
      item['eyeStatus'] = !status;
    },
    go(url, item) {
      uni.navigateTo({
        url: `${url}?bank_id=${item.id}&card_no=${item.card_no}`
      })
    }
  },
  filters: {
    formatCard(val) {
      val = val.replace(/^(\d{4})\d{4}(\d+)/, "$1****$2");
      return val;
    }
  }
}
</script>

<style lang="less" scoped>
  .container {
    background: #f4f4f4;
    width: 100%;
    height: calc(100vh - 44px);
  }

  .card {
    margin: 15px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 0 10px 2px rgba(0, 0, 0, .1);
    font-size: 14px;
    .header,.content,.footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .header {
      padding: 10px 15px;
      .classify-icon {
        width: 32px;
        height: 32px;
        line-height: 32px;
        text-align: center;
        border-radius: 50%;
        background: rgb(252, 124, 119);
        color: #ffffff;
        display: inline-block;
      }
      .card-no {
        margin-left: 5px;
        font-weight: bold;
        font-size: 18px;
      }
      .tips {
        color: #999;
        margin-left: 5px;
      }
    }
    .content {
      padding: 10px 15px;
      .surplus {
        color: #777;
      }
      .value {
        font-size: 18px;
        font-weight: bold;
      }
      .eye {
        position: relative;
        top: 1px;
        right: -10px;
      }
    }
    .footer {
      border-top: 1px solid #eee;
    }
    .footer>div {
      height: 40px;
      flex: 1;
      border: 1px solid #eee;
      text-align: center;
      line-height: 40px;
    }
  }
</style>